package com.yunfei.procedure;
import com.yunfei.api.v2.param.heTongLuRu.HeTongLuRuParam;
import com.yunfei.utils.jdbc.AiiidbUtil;
import oracle.jdbc.OracleTypes;
import java.sql.*;

/**
* @Description: 系统自动提交合同信息
* @Author: zhengyunfei
* @Date: 2019/2/15
* @time:16:44
*/
public class AutoSubmitContractInfoProcedure {
    private Connection conn;
    private CallableStatement stat;
    private ResultSet rs;
    String cllSql = "call PKG_YL_HIS_DATA.sp_appcreatecontract(?,?,?,?,?,?,?,?,?,?,?,?)";
    /**
    * @Description: 录入合同信息
    * @return: int 0成功其他失败
    * @Author: zhengyunfei
    * @Date: 2018/4/24
    * @time:13:49
    */
    public ProcedureResultModel callProcedure(AiiidbUtil aiiidbUtil, HeTongLuRuParam param, String reserveNo) {
        ProcedureResultModel result=new ProcedureResultModel();
        try {
            String url=aiiidbUtil.getJdbcUrl();
            String driverName=aiiidbUtil.getDriveClassName();
            String username=aiiidbUtil.getJdbcUserName();
            String password=aiiidbUtil.getJdbcPassword();
            Class.forName(driverName);
            conn = DriverManager.getConnection(url, username, password);
            stat = conn.prepareCall(cllSql);
            String proserialNo=param.getlProserialNo();
            String fBalance=param.getfBalance();
            String createDate=param.getCreateDate();
            String capitalDate=param.getdCapitalDate();
            String bankNo=param.getBankNo();
            String subBankNm=param.getSubBankNm();
            String acctNo=param.getAcctNo();
            String nameInBank=param.getNameInBank();
            String constactNum=param.getContractNum();
            stat.setString(1, reserveNo);//预约编号
            stat.setString(2, proserialNo);//项目编号
            stat.setString(3, fBalance);//合同金额
            stat.setString(4, createDate);//合同签署日期
            stat.setString(5, capitalDate);//起息日
            stat.setString(6, bankNo);//开户行
            stat.setString(7, subBankNm);//开户支行
            stat.setString(8, acctNo);//开户账号
            stat.setString(9, nameInBank);//开户姓名
            stat.setString(10, constactNum);//合同编号
            stat.registerOutParameter(11, OracleTypes.VARCHAR);
            stat.registerOutParameter(12, OracleTypes.VARCHAR);
            stat.execute();
            String returnCode= stat.getString(11);//处理结果 0:失败 1成功
            String returnInfo= stat.getString(12);//处理结果描述
            result.setReturnCode(returnCode);
            result.setReturnInfo(returnInfo);
            System.out.println("合同信息录入存储过程返回结果: " + result);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            close(conn, stat, rs);
        }
        return result;
    }

    // 关闭连接
    public void close(Connection conn, CallableStatement stat, ResultSet rs) {
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                rs = null;
            }
        }
        if (stat != null) {
            try {
                stat.close();
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                stat = null;
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                conn = null;
            }
        }
    }

    public static void main(String[] args) {
       // new GetTouZiZheRenZhengInfoProcedure().callProcedure("20180417132146779447466");
    }
}